package com.feihong.txgw.tx_precenter;

import com.feihong.txgw.inter.contract.integral.IFriendContract;
import com.feihong.txgw.model.bean.invitefriend.InviteFriendsEntity;
import com.feihong.txgw.model.bean.invitefriend.InviteFriendsResponseEntity;
import com.feihong.txgw.tx_model.InviteFriendMainModel;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName InviteFriendsPrecenter
 * @package com.feihong.txgw.tx_precenter
 * @data 2018/5/3 18:09
 * @Describe
 * @Change
 */
public class InviteFriendsPrecenter extends IFriendContract.AbFriendMainPrecenter {

    public static InviteFriendsPrecenter create(){
        return new InviteFriendsPrecenter();
    }

    @Override
    public IFriendContract.IFriendMainModel getModel() {
        return InviteFriendMainModel.create();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void loadFriendsInfo(String cacheKey) {
        mIModel.getFriendsInfo(cacheKey).subscribe(new Observer<InviteFriendsResponseEntity>() {
            @Override
            public void onSubscribe(Disposable d) {
                mRxManager.register(d);
            }

            @Override
            public void onNext(InviteFriendsResponseEntity info) {
                if(200 == info.getCode()){
                    List<InviteFriendsEntity> list = info.getData();
                    mIView.setFriendsInfo(list);
                }else if(8002 == info.getCode()){
                    mIView.notData();
                }else {
                    mIView.otherErrorMsg(info.getMsg());
                }
            }

            @Override
            public void onError(Throwable e) {
                mIView.loadDataError();
            }

            @Override
            public void onComplete() {
                mIView.loadDataComplated();
            }
        });
    }

    @Override
    public void loadFriendsInfoFirst(String cacheKey) {
        loadFriendsInfo(cacheKey);
    }
}
